package com.example.myapplication;

import android.app.Application;
import android.content.Context;

import com.database.dao.DaoMaster;
import com.database.dao.DaoSession;


@SuppressWarnings("unused")
public class MyApplication extends Application {
    public static MyApplication DAO;
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;
    private static final String databaseName = "testdb";


    @Override
    public void onCreate() {
        super.onCreate();
        if (DAO == null)


            DAO = this;
    }

    public static DaoMaster getDaoMaster(Context context) {
        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), databaseName);
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return daoMaster;
    }

    public static DaoSession getDaoSession(Context context) {
        if (daoSession == null) {
            if (daoMaster == null) {
                daoMaster = getDaoMaster(context);
            }
            daoSession = daoMaster.newSession();
        }
        return daoSession;
    }
}
